﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HttpCrawler.Engine.Test.Internal;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HttpCrawler.Engine.Test
{
    [TestClass]
    public class CssHttpCrawlerContentProcessorTests
    {
        [TestMethod]
        public void Process_Extracts_Expected_Links()
        {
            var httpCrawlerContent = StringHttpCrawlerContent.CreateUninitialized();
            var cssStringBuilder = new StringBuilder();
            cssStringBuilder.Append(@"url(http://f\,oo/bar)");
            cssStringBuilder.Append(@"url('http://foo/bar2')");
            cssStringBuilder.Append(@"url(http://f\""oo/ba\)r3)");
            cssStringBuilder.Append(@"url('http://fo\'o/ba\(r4')");

            httpCrawlerContent.OverrideText = cssStringBuilder.ToString();
            var target = new CssHttpCrawlerContentProcessor();
            var links = target.Process(httpCrawlerContent);

            var expectedLinks = new[] 
            { 
                "http://f,oo/bar", 
                "http://foo/bar2", 
                "http://f\"oo/ba)r3", 
                "http://fo'o/ba(r4", 
            };

            CollectionAssert.AreEquivalent(expectedLinks, links.ToArray());
        }
    }
}
